initEmployee();
function initEmployee() {
  $.ajax({
    url: '/emoloyee.do',
    method: 'GET',
    success: function (result) {
      if (result && result.length > 0) {
        for (var i = 0; i < result.length; i++) {
          var val = result[i];
          $(`<tr>
                <td><img  src="/assets/img/${val.photo}"/></td>
                <td>${val.id}</td>
                <td>${val.name}</td>
                <td>${val.sex}</td>
                <td>${val.age}</td>
                <td>${val.phone}</td>
                <td>${val.idCard}</td>
                <td>${val.role}</td>
                <td>
                  <a class="am-btn am-btn-success modify" href="addEmployee.html?id=${val.id}">修改</a>
                  <button class="am-btn am-btn-danger remove" myId="${val.id}">删除</button>
                </td>
            </tr>`).appendTo('tbody');
        }
      }
    }
  })
}

$(document).on('click','.remove',function(){
  let id = $(this).attr('myId');
  $.post('/remove_employee.do',{id},function(result){
    if(result=='success'){
      swal('成功','删除成功','success');
    }else{
      swal('失败','删除失败','error');
    }
  })
})